#include "rd_protocol.h"
#include "app_can.h"
/**
 * @brief 无线通信协议，自定义协议,鑫丰自定义协议遥控器
 */

uint8_t ucOwnProtocolBuf[OWN_PROTOCOL_NREGS] = { 0 };
void ownProtocol_FrameAnalysis(uint8_t *pbuf,size_t len)
{
    uint8_t i  = 0;
    if(pbuf[0] == 0xC0)
    {
        for(i = 0;i < OWN_PROTOCOL_NREGS;i++)
        {
            ucOwnProtocolBuf[i] = pbuf[OWN_PROTOCOL_NREGS-i];
        }
    }
}
/**
 * @brief 从自定义协议中读取一个8位数据
 */
uint8_t ucOwn_readOneRegProtocol(uint8_t reg)
{
    return ucOwnProtocolBuf[reg];
}
uint8_t uc_rd_online = 0;/*modbus RTU,无线在线标志*/
uint8_t uc_rd_s12 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s13 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s14 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s21 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s22 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s23 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s24 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s31 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s32 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s33 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s34 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s41 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s42 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s43 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s44 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s51 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s52 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s53 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s54 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s61 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s62 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s63 = 0;/*modbus RTU,按键 无线手柄*/
uint8_t uc_rd_s64 = 0;/*modbus RTU,按键 无线手柄*/
void clear_rd_rx(void)
{
    uc_rd_online = 0;
    uc_rd_s12 = 0;
    uc_rd_s13 = 0;
    uc_rd_s14 = 0;
    uc_rd_s21 = 0;
    uc_rd_s22 = 0;
    uc_rd_s23 = 0;
    uc_rd_s24 = 0;
    uc_rd_s31 = 0;
    uc_rd_s32 = 0;
    uc_rd_s33 = 0;
    uc_rd_s34 = 0;
    uc_rd_s41 = 0;
    uc_rd_s42 = 0;
    uc_rd_s43 = 0;
    uc_rd_s44 = 0;
    uc_rd_s51 = 0;
    uc_rd_s52 = 0;
    uc_rd_s53 = 0;
    uc_rd_s54 = 0;
    uc_rd_s61 = 0;
    uc_rd_s62 = 0;
    uc_rd_s63 = 0;
    uc_rd_s64 = 0;
}
/**
 * @brief 自定义协议数据处理
 */
void uc_rd_dataHandler(void)
{
    uint8_t temp = 0;

    temp = ucOwn_readOneRegProtocol(0);
    uc_rd_online = (temp>>0)&0x01;

    if(uc_rd_online == 0) 
    {
		clear_rd_rx();
        return;
        
    }
    uc_rd_s12    = (temp>>1)&0x01;
    uc_rd_s13    = (temp>>2)&0x01;
    uc_rd_s14    = (temp>>3)&0x01;
    uc_rd_s21    = (temp>>4)&0x01;
    uc_rd_s22    = (temp>>5)&0x01;
    uc_rd_s23    = (temp>>6)&0x01;
    uc_rd_s24    = (temp>>7)&0x01;
    temp = ucOwn_readOneRegProtocol(1);
    uc_rd_s31    = (temp>>0)&0x01;
    uc_rd_s32    = (temp>>1)&0x01;
    uc_rd_s33    = (temp>>2)&0x01;
    uc_rd_s34    = (temp>>3)&0x01;
    uc_rd_s41    = (temp>>4)&0x01;
    uc_rd_s42    = (temp>>5)&0x01;
    uc_rd_s43    = (temp>>6)&0x01;
    uc_rd_s44    = (temp>>7)&0x01;
    temp = ucOwn_readOneRegProtocol(2);
    uc_rd_s51    = (temp>>0)&0x01;
    uc_rd_s52    = (temp>>1)&0x01;
    uc_rd_s53    = (temp>>2)&0x01;
    uc_rd_s54    = (temp>>3)&0x01;
    uc_rd_s61    = (temp>>4)&0x01;
    uc_rd_s62    = (temp>>5)&0x01;
    uc_rd_s63    = (temp>>6)&0x01;
    uc_rd_s64    = (temp>>7)&0x01;

    g_out_timeout_cntr = 0;
}




